Lab 01 - Introduction

Robotics II

Poznan University of Technology, Institute of Robotics and Machine Intelligence

Laboratory 1: Introduction to Formula Student Driverless Simulator

Back to the course table of contents

1. Formula Student Driverless Simulator

Formula Student is an international series of engineering competitions organized by Society of Automotive Engineers (SAE). The contest consists of static and dynamic events. Dynamic events include Skid Pad, Acceleration, Autocross, and Endurance.

Formula Student Driverless is a dedicated class of Formula Student racecars to autonomous vehicles. This type was launched in 2017 at Formula Student Germany. In Driverless competitions instead of Endurance events, Trackdrive is held. The figure below depicts Trackdrive track marking.

Formula Student Driverless Simulator is a community-based project whose goal was to provide an end-to-end simulation for FS Driverless teams. The simulator was also used in online competitions FS-Online 2020.

Docker image used during laboratories is based on: - Formula-Student-Driverless-Simulator - ROS2 humble (in docker) - NVIDIA docker image with Vulkan and CUDAGL

2. Requirements

2.1. Hardware

*  recommended system requirements:
    - 8 core 2.3Ghz CPU
    - 12 GB memory
    - 30GB free SSD storage
    - NVidia card with Vulkan support and 3 GB of memory

* testing machine:
    - OS: Ubuntu 20.04.1 LTS 64-bit
    - Intel® Core™ i5-8400 CPU @ 2.80GHz × 6
    - RAM 15.6 GiB
    - GeForce GTX 1060 6GB

* docker image size is about 9 GB

2.2. Software

3. Installation

You have two ways, you can try configure whole FSDS simulator with ROS2 by yourself or follow the steps from instruction.

Help for your steps

Your configuration probably would be fine if you are able to do exercises from 5th part of this instruction…

Instruction steps

  1. Download fsds-v2.2.0-linux.zip on your computer from github: link

  2. Create a new workspace on your computer.

  3. Unzip fsds-v2.2.0-linux.zip to your new workspace.

  unzip fsds-v2.2.0-linux.zip -d ./fsds_bin
  1. Create 2 folders in your workspace fsds-data and ros2_ws

  2. Create .env file:

  ROS_DISTRO=humble
  1. Create Dockerfile.fsds-sim
  ARG BASE_IMAGE=nvidia/vulkan:1.1.121-cuda-10.1-beta.1-ubuntu18.04
FROM ${BASE_IMAGE}

ENV DEBIAN_FRONTEND=noninteractive

# Fix NVIDIA CUDA repo (cuda-keyring) + de-dupe entries
RUN set -eux; \
    mkdir -p /tmp/apt-disabled; \
    for f in /etc/apt/sources.list.d/*nvidia* /etc/apt/sources.list.d/*cuda*; do \
        [ -f "$f" ] && mv "$f" /tmp/apt-disabled/ || true; \
    done; \
    apt-get update; \
    apt-get install -y --no-install-recommends ca-certificates wget dpkg; \
    wget -q https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-keyring_1.1-1_all.deb -O /tmp/cuda-keyring.deb; \
    dpkg -i /tmp/cuda-keyring.deb; \
    rm -f /tmp/cuda-keyring.deb; \
    for f in /tmp/apt-disabled/*; do \
        [ -f "$f" ] && mv "$f" /etc/apt/sources.list.d/ || true; \
    done; \
    rmdir /tmp/apt-disabled || true; \
    for f in /etc/apt/sources.list /etc/apt/sources.list.d/*.list; do \
        [ -f "$f" ] && sed -i '\|developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64|d' "$f" || true; \
    done; \
    echo "deb [signed-by=/usr/share/keyrings/cuda-archive-keyring.gpg] https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64 /" \
      > /etc/apt/sources.list.d/cuda.list; \
    apt-get update; \
    rm -rf /var/lib/apt/lists/*

# runtime deps for GUI + audio
RUN apt-get update && apt-get install -y --no-install-recommends \
      libglu1-mesa \
      libvulkan1 \
      mesa-vulkan-drivers \
      vulkan-utils \
      pulseaudio \
      x11-xserver-utils \
      wget \
      unzip \
    && rm -rf /var/lib/apt/lists/*

# FSDS binaries
# Create non-root user (FSDS refuses to run as root)
RUN useradd -m -s /bin/bash fsds && \
    usermod -aG audio,video fsds

# FSDS install dir with correct ownership
RUN mkdir -p /opt/fsds && chown -R fsds:fsds /opt/fsds

# Copy FSDS binaries
COPY fsds_bin/ /opt/fsds/
RUN chown -R fsds:fsds /opt/fsds

# Start wrapper (auto-detect launcher)
RUN cat > /opt/fsds/run_fsds.sh <<'EOF'
#!/usr/bin/env bash
set -e
cd /opt/fsds
if [ -x ./FSDS.sh ]; then
  exec ./FSDS.sh -settings /opt/fsds/settings.json
elif [ -x ./FSDS/Binaries/Linux/FSDS ]; then
  exec ./FSDS/Binaries/Linux/FSDS -settings /opt/fsds/settings.json
else
  echo "ERROR: cannot find FSDS launcher."
  ls -la /opt/fsds | head -n 200
  exit 1
fi
EOF
RUN chmod +x /opt/fsds/run_fsds.sh && chown fsds:fsds /opt/fsds/run_fsds.sh

USER fsds
WORKDIR /home/fsds
  1. Create Dockerfile.ros2
  ARG ROS_DISTRO=humble
FROM ros:${ROS_DISTRO}-ros-base-jammy

ENV DEBIAN_FRONTEND=noninteractive
ENV CPLUS_INCLUDE_PATH=/usr/include/eigen3:${CPLUS_INCLUDE_PATH}

ARG ROS_DISTRO

RUN apt-get update && apt-get install -y --no-install-recommends \
    software-properties-common \
    && add-apt-repository -y universe \
    && apt-get update \
    && apt-get install -y --no-install-recommends \
    python3-pip \
    python3-colcon-common-extensions \
    python3-rosdep \
    git \
    libboost-filesystem-dev \
    libboost-system-dev \
    gazebo \
    libgazebo-dev \
    libeigen3-dev \
    libboost-filesystem-dev \
    libboost-system-dev \
    libopencv-dev \
    libsodium-dev \
    libzmq3-dev \
    gazebo \
    libgazebo-dev \
    ros-${ROS_DISTRO}-cv-bridge \
    ros-${ROS_DISTRO}-image-transport \
    ros-${ROS_DISTRO}-ament-cmake \
    ros-${ROS_DISTRO}-ament-cmake-auto \
    ros-${ROS_DISTRO}-rosidl-default-generators \
    ros-${ROS_DISTRO}-ament-lint-auto \
    ros-${ROS_DISTRO}-rviz2 \
    ros-${ROS_DISTRO}-rviz-common \
    ros-${ROS_DISTRO}-rviz-default-plugins \
    ros-${ROS_DISTRO}-rqt \
    ros-${ROS_DISTRO}-rqt-common-plugins \
&& rm -rf /var/lib/apt/lists/*


RUN mkdir -p /ros2_ws/src/fsds
WORKDIR /ros2_ws

RUN git clone --recurse-submodules --depth=1 https://github.com/FS-Driverless/Formula-Student-Driverless-Simulator.git /opt/fsds_repo
RUN cp -a /opt/fsds_repo/ros2/src/* /ros2_ws/src/fsds/
RUN ln -s /opt/fsds_repo/AirSim /ros2_ws/AirSim

RUN bash -lc "rosdep init || true && rosdep update"
RUN bash -lc "source /opt/ros/${ROS_DISTRO}/setup.bash && \
    rosdep install --from-paths src --ignore-src -r -y"
  1. Create docker-compose.yml
  services:
    fsds-sim:
      build:
        context: .
        dockerfile: Dockerfile.fsds-sim
        args:
          BASE_IMAGE: nvidia/vulkan:1.1.121-cuda-10.1-beta.1-ubuntu18.04
      image: fsds-sim:ubuntu18
      network_mode: host
      shm_size: "4gb"

      runtime: nvidia

      environment:
        - DISPLAY=${DISPLAY}
        - NVIDIA_VISIBLE_DEVICES=all
        - NVIDIA_DRIVER_CAPABILITIES=compute,graphics,utility,display
        - SDL_AUDIODRIVER=pulse
        - PULSE_SERVER=unix:${XDG_RUNTIME_DIR}/pulse/native

      volumes:
        - /tmp/.X11-unix:/tmp/.X11-unix:rw
        - ${XDG_RUNTIME_DIR}/pulse/native:${XDG_RUNTIME_DIR}/pulse/native:rw
        - ~/.config/pulse/cookie:/root/.config/pulse/cookie:ro
        - ./settings.json:/opt/fsds/settings.json:ro
        - ./fsds-data:/root/.fsds


      command: ["/opt/fsds/run_fsds.sh"]

    fsds-ros2:
      build:
        context: .
        dockerfile: Dockerfile.ros2
        args:
          ROS_DISTRO: ${ROS_DISTRO:-humble}
      image: fsds-ros2:${ROS_DISTRO:-humble}
      network_mode: host
      environment:
        - ROS_DOMAIN_ID=0
        - RMW_IMPLEMENTATION=rmw_fastrtps_cpp
        - ROS_DISTRO=${ROS_DISTRO:-humble}
        - DISPLAY=${DISPLAY}
        - QT_X11_NO_MITSHM=1
      volumes:
        - ./ros2_ws:/ws
        - /tmp/.X11-unix:/tmp/.X11-unix:rw
      command: ["/bin/bash", "-lc", "source /opt/ros/$ROS_DISTRO/setup.bash && sleep infinity"]
  1. Create and copy settings.json from github site link

3.5 Run

  1. Add docker access to Nvidia and display

NOTE: This step is required in every new terminal session if it needs to run GUI applications (like simulator, rviz, rqt_plot).

xhost + local:root
  1. Just run docker compose
docker compose up
  1. Get into the running ROS2 container from another terminal
docker compose exec fsds-ros2 bash
  1. Source ROS2:
source /opt/ros/humble/setup.bash
  1. Change the settings.json path in src/fsds/fsds_ros2_bridge/launch/fsds_ros2_bridge.launch.py file from:
expanduser("~")+'/Formula-Student-Driverless-Simulator/settings.json'

to:

/opt/fsds_repo/settings.json
  1. Build ROS2 packages:
colcon build --symlink-install
  1. Source again but now to:
source install/setup.bash

4. Simulator usage

Simulator

Simulator starting simultanously with container, the menu should be opened and you can choose the maps.

Robot Operating System 2

5. Tasks

  1. Run container and check if everything works correctly.

  2. Start the simulator, check available maps, and move the racecar using a keyboard.

  3. Connect ROS2 with simulator using fsds_ros2_bridge package and check available topics and services. Then compare the list with documentation.

  4. Create your own ROS2 package and create sine_steering_node.py in which you should implement steering method for race car based on sine signal. Use

OUTCOME TASK

As a laboratory outcome take and add to the eKursy platform two screenshots of:

and your implementation of sine_steering_node.py.